<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
    <h:head>
    </h:head>

    <h:body>
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{bundle['dataset.widgets.title']} - #{DatasetWidgetsPage.dataset.latestVersion.title}"/>
            <ui:param name="dataverse" value="#{DatasetWidgetsPage.dataset.owner}"/>
            <ui:param name="dataset" value="#{DatasetWidgetsPage.dataset}"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:define name="body">
                <f:metadata>
                    <f:viewParam name="datasetId" value="#{DatasetWidgetsPage.datasetId}"/>
                    <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
                    <f:viewAction action="#{DatasetWidgetsPage.init}" />
                    <f:viewAction action="#{dataverseHeaderFragment.initBreadcrumbs(DatasetWidgetsPage.dataset, bundle['dataset.thumbnailsAndWidget.breadcrumbs.title'])}"/>
                </f:metadata>
                <p:tabView rendered="#{themeWidgetFragment.editDv!=null}" id="themeWidgetsTabView" widgetVar="content">
                    <p:tab id="thumbnailsTab" title="#{bundle['dataset.thumbnailsAndWidget.thumbnails.title']}">
                        <h:form id="themeWidgetsForm" styleClass="row form-horizontal">
                            <div class="form-group" jsf:rendered="#{true or themeWidgetFragment.editDv.themeRoot}">
                                <label class="col-sm-3 control-label" for="logoFormat">
                                    #{bundle['dataset.thumbnailsAndWidget.thumbnailImage']}
                                    <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                          data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.title']}"></span>
                                </label>
                                <div class="col-sm-9">
                                    <p class="help-block">
                                        <h:outputFormat value="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.tip']}" escape="false">
                                            <f:param value="#{systemConfig.uploadLogoSizeLimit/1000}"/>
                                        </h:outputFormat>
                                    </p>
                                    <div id="thumbnailPreview" class="col-sm-2 text-center">
                                        <p>
                                            <span class="icon-dataset text-info" style="font-size: 2.8em;" jsf:rendered="#{DatasetWidgetsPage.datasetThumbnail == null}"/>
                                            <h:graphicImage value="#{DatasetWidgetsPage.datasetThumbnail.base64image}" alt="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.alt']}" rendered="#{DatasetWidgetsPage.datasetThumbnail != null}"/>
                                        </p>
                                        <span class="text-muted" jsf:rendered="#{DatasetWidgetsPage.datasetThumbnail == null}"><em>#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.default']}</em></span>
                                        <p:commandButton update="@form" value="#{bundle.remove}" action="#{DatasetWidgetsPage.flagDatasetThumbnailForRemoval()}" rendered="#{DatasetWidgetsPage.datasetThumbnail != null and DatasetWidgetsPage.datasetThumbnail.fromDataFile != true}" oncomplete="bind_bsui_components();"/>
                                        <div jsf:rendered="#{DatasetWidgetsPage.datasetThumbnail.fromDataFile == true}">
                                            <button class="btn btn-default" onclick="PF('confrmRemove').show()" type="button">
                                                #{bundle.remove}
                                            </button>
                                        </div>
                                    </div>
                                    <div class="col-sm-8">
                                        <div class="form-group" jsf:rendered="#{not empty DatasetWidgetsPage.datasetThumbnails}">
                                            <label for="selectThumbnail" class="control-label">
                                                #{bundle['dataset.thumbnailsAndWidget.thumbnailImage.selectAvailable']}
                                                <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                                      data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.selectAvailable.title']}"></span>
                                            </label>
                                            <div>
                                                <button class="btn btn-default" onclick="PF('selectFileThumbnail').show()" type="button">
                                                    #{bundle['dataset.thumbnailsAndWidget.thumbnailImage.selectThumbnail']}
                                                </button>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="uploadThumbnail" class="control-label">
                                                #{bundle['dataset.thumbnailsAndWidget.thumbnailImage.uploadNew']}
                                                <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                                      data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.uploadNew.title']}"></span>
                                            </label>
                                            <p:fileUpload invalidFileMessage="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.upload.invalidMsg']}" id="changelogo" allowTypes="/(\.|\/)(jpg|jpeg|tff|png|gif)$/" update="@form" 
                                                          sizeLimit="#{systemConfig.uploadLogoSizeLimit}" 
                                                          oncomplete="bind_bsui_components();" dragDropSupport="true" auto="true" multiple="false" 
                                                          fileUploadListener="#{DatasetWidgetsPage.handleImageFileUpload}" label="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.upload']}"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="button-block">
                                <p:commandButton styleClass="btn btn-default" update="@form" value="#{bundle.saveChanges}" action="#{DatasetWidgetsPage.save()}"/>
                                <p:commandButton styleClass="btn btn-link" update="@form" value="#{bundle.cancel}" action="#{DatasetWidgetsPage.cancel()}"/>
                            </div>

                            <p:dialog id="confrmRemove" header="#{bundle['dataset.thumbnailsAndWidget.removeThumbnail']}" widgetVar="confrmRemove" modal="true">
                                <p class="help-block">
                                    <span class="glyphicon glyphicon-warning-sign text-warning"/> <span class="text-warning">#{bundle['dataset.thumbnailsAndWidget.removeThumbnail.tip']}</span>
                                </p>
                                <div class="button-block">
                                    <p:commandButton value="#{bundle.continue}" styleClass="btn btn-default" onclick="PF('confrmRemove').hide()"
                                                   action="#{DatasetWidgetsPage.flagDatasetThumbnailForRemoval()}"
                                                   update="@form"/>
                                    <button class="btn btn-link" onclick="PF('confrmRemove').hide()" type="button">
                                        #{bundle.cancel}
                                    </button>
                                </div> 
                            </p:dialog>
                            <p:dialog id="selectFileThumbnail" header="#{bundle['dataset.thumbnailsAndWidget.availableThumbnails']}" widgetVar="selectFileThumbnail" modal="true">
                                <div class="form-horizontal col-sm-12">
                                    <div class="form-group">
                                        <p class="help-block">#{bundle['dataset.thumbnailsAndWidget.availableThumbnails.tip']}</p>
                                        <p:outputPanel id="customPanel">
                                            <p:selectOneRadio id="selectDatasetThumbnail" value="#{DatasetWidgetsPage.datasetFileThumbnailToSwitchTo}" layout="custom" converter="dataFileConverter">
                                                <f:selectItems value="#{DatasetWidgetsPage.datasetThumbnails}" var="thumb" itemLabel="#{thumb}" itemValue="#{thumb.dataFile}"/>
                                            </p:selectOneRadio>
                                            <c:forEach items="#{DatasetWidgetsPage.datasetThumbnails}" var="thumbnail" varStatus="loop">
                                                <div class="col-xs-4 text-center radio">
                                                    <p:radioButton for="selectDatasetThumbnail" id="opt#{loop.index}" itemIndex="#{loop.index}" />
                                                    <h:outputLabel for="opt#{loop.index}" style="padding:4px;">
                                                        <div style="height:48px;"><img src="#{thumbnail.base64image}" alt="#{thumbnail.filename}"/></div>
                                                        <h:outputText value="#{thumbnail.filename}"/>
                                                    </h:outputLabel>
                                                </div>
                                            </c:forEach>
                                        </p:outputPanel>
                                    </div>
                                </div>
                                <div class="button-block">
                                    <p:commandButton styleClass="btn btn-default" update="@form" value="#{bundle.continue}" action="#{DatasetWidgetsPage.setDataFileAsThumbnail()}"/>
                                    <button class="btn btn-link" onclick="PF('selectFileThumbnail').hide()" type="button">
                                        #{bundle.cancel}
                                    </button>
                                </div>
                            </p:dialog>
                        </h:form>
                    </p:tab>
                    <!-- modify by yqpeng2，2019-12-16 隐藏 -->
                    <p:tab id="widgetsTab" title="#{bundle['dataset.thumbnailsAndWidget.widgets.title']}" rendered="false">
                        <div id="no-widgets-message" class="panel panel-default" jsf:rendered="#{DatasetWidgetsPage.dataset.id.intValue() > 0 and !DatasetWidgetsPage.dataset.released}">
                            <div class="panel-body">
                                <span class="help-block h3">#{bundle['dataset.widgets.notPublished.why.header']}</span>
                                <ul>
                                    <li><h:outputText value="#{bundle['dataset.widgets.notPublished.why.reason1']}" escape="false"/></li>
                                    <li><h:outputText value="#{bundle['dataset.widgets.notPublished.why.reason2']}" escape="false"/></li>
                                </ul>
                                <span class="help-block h3">#{bundle['dataset.widgets.notPublished.how.header']}</span>
                                <ul>
                                    <li><h:outputText value="#{bundle['dataset.widgets.notPublished.how.tip1']}" escape="false"/></li>
                                    <li><h:outputText value="#{bundle['dataset.widgets.notPublished.how.tip2']}" escape="false"/></li>
                                    <li>
                                        <h:outputFormat value="#{bundle['dataset.widgets.notPublished.how.tip3']}" escape="false">
                                            <f:param value="#{systemConfig.guidesBaseUrl}"/>
                                            <f:param value="#{systemConfig.guidesVersion}"/>
                                        </h:outputFormat>
                                    </li>
                                </ul>
                                <p>
                                    <h:outputFormat value="#{bundle['dataset.widgets.notPublished.getStarted']}" escape="false">
                                        <f:param value="#{systemConfig.guidesBaseUrl}"/>
                                        <f:param value="#{systemConfig.guidesVersion}"/>
                                    </h:outputFormat>
                                </p>
                            </div>
                        </div>

                        <ui:fragment rendered="#{DatasetWidgetsPage.dataset.released}">
                            <p class="help-block">
                                <h:outputFormat value="#{bundle['dataset.widgets.tip']}" escape="false">
                                    <f:param value="#{systemConfig.guidesBaseUrl}"/>
                                    <f:param value="#{systemConfig.guidesVersion}"/>
                                </h:outputFormat>
                            </p>
                            <div>
                                <h5>
                                    #{bundle['dataset.widgets.citation.txt']}
                                </h5>
                                <p class="help-block">#{bundle['dataset.widgets.citation.tip']}</p>
                            </div>
                            <div>
                                <textarea rows="3" cols="54" class="form-control">&lt;script src=&quot;#{systemConfig.dataverseSiteUrl}/resources/js/widgets.js?persistentId=#{dataset.globalId}&amp;amp;dvUrl=#{systemConfig.dataverseSiteUrl}&amp;amp;widget=citation&amp;amp;heightPx=150&quot;&gt;&lt;/script&gt;</textarea>
                            </div>
                            <div>
                                <h5>
                                    #{bundle['dataset.widgets.datasetFull.txt']}
                                </h5>
                                <p class="help-block">#{bundle['dataset.widgets.datasetFull.tip']}</p>
                            </div>
                            <div>
                                <textarea rows="3" cols="54" class="form-control">&lt;script src=&quot;#{systemConfig.dataverseSiteUrl}/resources/js/widgets.js?persistentId=#{dataset.globalId}&amp;amp;dvUrl=#{systemConfig.dataverseSiteUrl}&amp;amp;widget=iframe&amp;amp;heightPx=500&quot;&gt;&lt;/script&gt;</textarea>
                            </div>
                        </ui:fragment>
                        <div class="button-block">
                            <h:outputLink class="btn btn-default" value="/dataset.xhtml?persistentId=#{DatasetWidgetsPage.dataset.globalIdString}">
                                <h:outputText value="#{bundle.done}"/></h:outputLink>
                        </div>
                    </p:tab>
                </p:tabView>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
